Conditions | 1 |
Paths | 1 |
Total Lines | 111 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | $(document).ready(function () { |
||
2 | function closeDoorhanger() { |
||
3 | API.runtime.sendMessage(API.runtime.id, { |
||
4 | method: "passToParent", |
||
5 | args: {'injectMethod': 'closeDoorhanger'} |
||
6 | }); |
||
7 | } |
||
8 | var dh = $('#password-doorhanger'); |
||
9 | var btn_config = { |
||
10 | 'cancel': function () { |
||
11 | return { |
||
12 | text: API.i18n.getMessage('cancel'), |
||
13 | onClickFn: function () { |
||
14 | API.runtime.sendMessage(API.runtime.id, { |
||
15 | method: "passToParent", |
||
16 | args: {'injectMethod': 'closeDoorhanger'} |
||
17 | }); |
||
18 | API.runtime.sendMessage(API.runtime.id, {method: "clearMined"}); |
||
19 | } |
||
20 | }; |
||
21 | }, |
||
22 | 'save': function (data) { |
||
23 | var save = API.i18n.getMessage('save'); |
||
24 | var update = API.i18n.getMessage('update'); |
||
25 | var btnText = (data.guid === null) ? save : update; |
||
26 | return { |
||
27 | text: btnText, |
||
28 | onClickFn: function () { |
||
29 | API.runtime.sendMessage(API.runtime.id, {method: "saveMined"}); |
||
30 | dh.find('.toolbar-text').text(API.i18n.getMessage('saving') + '...'); |
||
31 | dh.find('.passman-btn').hide(); |
||
32 | } |
||
33 | }; |
||
34 | }, |
||
35 | 'updateUrl': function (data) { |
||
36 | return { |
||
37 | text: 'Update', |
||
38 | onClickFn: function () { |
||
39 | API.runtime.sendMessage(API.runtime.id, {method: "updateCredentialUrl", args: data}); |
||
40 | dh.find('.toolbar-text').text('Saving...'); |
||
41 | dh.find('.passman-btn').hide(); |
||
42 | } |
||
43 | }; |
||
44 | }, |
||
45 | 'ignore': function (data) { |
||
46 | return { |
||
47 | text: API.i18n.getMessage('ignore_site'), |
||
48 | onClickFn: function () { |
||
49 | //closeToolbar(); |
||
50 | API.runtime.sendMessage(API.runtime.id, {method: "ignoreSite", args: data.currentLocation}); |
||
51 | dh.find('.toolbar-text').text(API.i18n.getMessage('site_ignored')); |
||
52 | dh.find('.passman-btn').hide(); |
||
53 | setTimeout(function () { |
||
54 | closeDoorhanger(); |
||
55 | }, 3000); |
||
56 | } |
||
57 | }; |
||
58 | } |
||
59 | }; |
||
60 | |||
61 | |||
62 | API.runtime.sendMessage(API.runtime.id, {method: "getDoorhangerData"}).then(function (data) { |
||
63 | if(!data){ |
||
64 | return; |
||
65 | } |
||
66 | var buttons = data.buttons; |
||
67 | data = data.data; |
||
68 | var displayUrl = data.url; |
||
69 | if(displayUrl.length > 512){ |
||
70 | displayUrl = displayUrl.substring(0,8); |
||
71 | } |
||
72 | var doorhanger_div = $('<div id="password-toolbar">'); |
||
73 | $('<span>', { |
||
74 | class: 'toolbar-text', |
||
75 | text: data.title + ' ' + data.username + ' at ' + displayUrl |
||
76 | }).appendTo(doorhanger_div); |
||
77 | |||
78 | |||
79 | $.each(buttons, function (k, button) { |
||
80 | button = btn_config[button](data); |
||
81 | var html_button = $('<button class="passman-btn passnman-btn-success"></button>').text(button.text); |
||
82 | html_button.click(button.onClickFn); |
||
83 | doorhanger_div.append(html_button); |
||
84 | }); |
||
85 | dh.html(doorhanger_div); |
||
86 | }); |
||
87 | |||
88 | var _this = {}; |
||
89 | |||
90 | function minedLoginSaved(args) { |
||
91 | // If the login added by the user then this is true |
||
92 | |||
93 | var saved = API.i18n.getMessage('credential_saved'); |
||
94 | var updated = API.i18n.getMessage('credential_updated'); |
||
95 | var action = (args.updated) ? updated : saved; |
||
96 | $('#password-toolbar').html(action + '!'); |
||
97 | //@TODO update |
||
98 | setTimeout(function () { |
||
99 | closeDoorhanger(); |
||
100 | }, 2500); |
||
101 | |||
102 | } |
||
103 | |||
104 | _this.minedLoginSaved = minedLoginSaved; |
||
105 | API.runtime.onMessage.addListener(function (msg, sender, sendResponse) { |
||
|
|||
106 | //console.log('Method call', msg.method); |
||
107 | if (_this[msg.method]) { |
||
108 | _this[msg.method](msg.args, sender); |
||
109 | } |
||
110 | }); |
||
111 | }); |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.